import { View } from "../../../mvc/core/View";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Language } from "../../../../extend/language/Language";
import { ECareer } from "../../../../Message/Public/ECareer";
import { ObjCreate } from "../common/ObjCreate";
import { SearchStringList } from "./SearchStringList";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { Cache } from "../../cache/Cache";
import { ItemInfo } from "../../resource/info/ItemInfo";
import { SearchConditionData } from "./SearchConditionData";
import { MsgManager } from "../../manager/MsgManager";
import { DataEvent } from "../../events/DataEvent";
import { EMarketOrder } from "../../../../Message/Game/EMarketOrder";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _ECareerWarrior } from "../../../../ECareer/_ECareerWarrior";
import { _ECareerArcher } from "../../../../ECareer/_ECareerArcher";
import { _ECareerFireMage } from "../../../../ECareer/_ECareerFireMage";
import { _ECareerDoctor } from "../../../../ECareer/_ECareerDoctor";
import { _ECareerWarriorD } from "../../../../ECareer/_ECareerWarriorD";
import { _ECareerStabber } from "../../../../ECareer/_ECareerStabber";
import { _ECareerIceMage } from "../../../../ECareer/_ECareerIceMage";
import { _ECareerPriest } from "../../../../ECareer/_ECareerPriest";
type int = number;
//class SearchCondition
    
    export  class SearchCondition extends View
    {
        constructor()
        {
            super();
            this._itemArr = [];
            this._searchDic = new Map<any, any> /* flash.utils.Dictionary */();
            this.initDp();
            this.init();
            Dispatcher.addEventListener(EventName.MarketSearchItemSelect, this.onSearchItemSelectHandler);
            return;
        }

        public get color(): int
        {
            return this._color;
        }

        public get career(): int
        {
            return this._career;
        }

        /* internal  */initDp(): void
        {
            this._levelDp = new DataProvider();
            this._levelDp.addItem({"id": 0, "low": 1, "upper": 100, "label": Language.getString(31014), "index": 0});
            this._levelDp.addItem({"id": 1, "low": 1, "upper": 9, "label": Language.getString(31015), "index": 1});
            this._levelDp.addItem({"id": 10, "low": 10, "upper": 19, "label": Language.getString(31016), "index": 2});
            this._levelDp.addItem({"id": 20, "low": 20, "upper": 29, "label": Language.getString(31017), "index": 3});
            this._levelDp.addItem({"id": 30, "low": 30, "upper": 39, "label": Language.getString(31018), "index": 4});
            this._levelDp.addItem({"id": 40, "low": 40, "upper": 49, "label": Language.getString(31019), "index": 5});
            this._levelDp.addItem({"id": 50, "low": 50, "upper": 59, "label": Language.getString(31020), "index": 6});
            this._levelDp.addItem({"id": 60, "low": 60, "upper": 100, "label": Language.getString(31021), "index": 7});
            this._colorDp = new DataProvider();
            this._colorDp.addItem({"id": 0, "label": Language.getString(31029), "index": 0});
            this._colorDp.addItem({"id": 1, "label": Language.getString(31030), "index": 1});
            this._colorDp.addItem({"id": 2, "label": Language.getString(31031), "index": 2});
            this._colorDp.addItem({"id": 3, "label": Language.getString(31032), "index": 3});
            this._colorDp.addItem({"id": 4, "label": Language.getString(31033), "index": 4});
            this._colorDp.addItem({"id": 5, "label": Language.getString(31034), "index": 5});
            this._careerDp = new DataProvider();
            this._careerDp.addItem({"id": 0, "label": Language.getString(31022), "index": 0});
            this._careerDp.addItem({"id": 17, "label": Language.getString(31073), "index": 9});
            this._careerDp.addItem({"id": 34, "label": Language.getString(31074), "index": 10});
            this._careerDp.addItem({"id": 68, "label": Language.getString(31075), "index": 11});
            this._careerDp.addItem({"id": 136, "label": Language.getString(31076), "index": 12});
            this._careerDp.addItem({"id": _ECareerWarrior, "label": Language.getString(31023), "index": 1});
            this._careerDp.addItem({"id": _ECareerArcher, "label": Language.getString(31024), "index": 2});
            this._careerDp.addItem({"id": _ECareerFireMage, "label": Language.getString(31025), "index": 3});
            this._careerDp.addItem({"id": _ECareerDoctor, "label": Language.getString(31026), "index": 4});
            this._careerDp.addItem({"id": _ECareerWarriorD, "label": Language.getString(31069), "index": 5});
            this._careerDp.addItem({"id": _ECareerStabber, "label": Language.getString(31070), "index": 6});
            this._careerDp.addItem({"id": _ECareerIceMage, "label": Language.getString(31071), "index": 7});
            this._careerDp.addItem({"id": _ECareerPriest, "label": Language.getString(31072), "index": 8});
            return;
        }

        /* internal  */init(): void
        {
            this._textInput = ObjCreate.createGTextInput(0, 0, 120, 25, this);
            this._textInput.text = Language.getString(31027);
            this._textInput.addEventListener(flash.events.Event.CHANGE, this.onTextInputChangeHandler);
            this._textInput.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.onTextInputFocusInHandler);
            this._textInput.addEventListener(flash.events.FocusEvent.FOCUS_OUT, this.onTextInputFocusOutHandler);
            this._searchBtn = ObjCreate.createGButton("", 125, 0, 23, 27, this, "MirrorButton");
            this._searchBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSearchBtnClickHandler);
            this._levelCombo = this.createComboBox(165, 0, 100, 25, this._levelDp);
            this._levelCombo.addEventListener(flash.events.Event.CHANGE, this.onLevelComboChangeHandler);
            this._colorCombo = this.createComboBox(275, 0, 100, 25, this._colorDp);
            this._colorCombo.addEventListener(flash.events.Event.CHANGE, this.onColorComboChangeHandler);
            this._careerCombo = this.createComboBox(385, 0, 100, 25, this._careerDp);
            this._careerCombo.addEventListener(flash.events.Event.CHANGE, this.onCareerComboChangeHandler);
            this._stringList = new SearchStringList();
            this._stringList.x = 0;
            this._stringList.y = 25;
            return;
        }

        /* internal  */createComboBox(arg1: int, arg2: int, arg3: int, arg4: int, arg5: DataProvider): GComboBox
        {
            var loc1;
            (loc1 = new GComboBox()).selectedIndex = 0;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.move(arg1, arg2);
            loc1.styleName = "GComboboxStyle";
            loc1.drawNow();
            loc1.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            loc1.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            loc1.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.CENTER));
            loc1.dataProvider = arg5;
            addChild(loc1);
            return loc1;
        }

        /* internal  */onTextInputChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc2=null;
            var loc1=this._textInput.text;
            if (loc1 == Language.getString(31027)) 
            {
                return;
            }
            if (loc1.length >= 1) 
            {
                this._itemArr.splice(0);
                this._itemArr = Cache.instance.market.getCodesByString(loc1);
                if (this._itemArr.length <= 0) 
                {
                    if (this._stringList.parent) 
                    {
                        removeChild(this._stringList);
                    }
                    return;
                }
                this._stringList.updateDataProvider(this._itemArr);
                addChild(this._stringList);
                if (this._itemArr.length == 1) 
                {
                    this._searchDic = new Map<any, any> /* flash.utils.Dictionary */();
                    loc2 = this._itemArr[0].itemInfo as ItemInfo;
                    this._searchDic[loc2.item.code] = loc2.item.code;
                    SearchConditionData.codesMap = this._searchDic;
                    if (loc1 == loc2.item.name) 
                    {
                        if (this._stringList.parent) 
                        {
                            removeChild(this._stringList);
                        }
                    }
                }
            }
            else if (this._stringList.parent) 
            {
                removeChild(this._stringList);
            }
            return;
        }

        /* internal  */onTextInputFocusInHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            if (!(this._textInput.text == "") && this._textInput.text == Language.getString(31027)) 
            {
                this._textInput.text = "";
                if (this._stringList.parent) 
                {
                    removeChild(this._stringList);
                }
            }
            return;
        }

        /* internal  */onTextInputFocusOutHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            if (this._textInput.text == "") 
            {
                this._textInput.text = Language.getString(31027);
            }
            return;
        }

        /* internal  */onSearchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._textInput.text;
            if (loc1 == Language.getString(31027)) 
            {
                return;
            }
            if (loc1.length < 1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(31111));
            }
            else 
            {
                SearchConditionData.codesMap = this._searchDic;
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSearch));
            }
            return;
        }

        /* internal  */onLevelComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._levelLower = this._levelCombo.selectedItem.low;
            this._levelUpper = this._levelCombo.selectedItem.upper;
            SearchConditionData.levelLower = this._levelLower;
            SearchConditionData.levelUpper = this._levelUpper;
            return;
        }

        /* internal  */onColorComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._color = this._colorCombo.selectedItem.id;
            SearchConditionData.color = this._color;
            return;
        }

        /* internal  */onCareerComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._career = this._careerCombo.selectedItem.id;
            SearchConditionData.career = this._career;
            return;
        }

        /* internal  */onSearchItemSelectHandler(arg1: DataEvent): void
        {
            var loc2=null;
            if (this._stringList && this._stringList.parent) 
            {
                removeChild(this._stringList);
            }
            var loc1=arg1.data as ItemInfo;
            if (loc1) 
            {
                this._searchDic = Cache.instance.market.getCodesByName(loc1.item.name);
                loc2 = loc1.item.name;
                this._textInput.text = loc2;
            }
            return;
        }

        public reset(): void
        {
            this._textInput.text = Language.getString(31027);
            this._levelCombo.selectedIndex = 0;
            this._colorCombo.selectedIndex = 0;
            this._careerCombo.selectedIndex = 0;
            this._stringList.updateDataProvider([]);
            this._levelLower = 1;
            this._levelUpper = 100;
            this._color = 0;
            this._career = 0;
            SearchConditionData.levelLower = this._levelLower;
            SearchConditionData.levelUpper = this._levelUpper;
            SearchConditionData.color = this._color;
            SearchConditionData.career = this._career;
            SearchConditionData.order = EMarketOrder._EMarketOrderNormal;
            return;
        }

        public setTextInputDefault(): void
        {
            this._textInput.text = Language.getString(31027);
            return;
        }

        public get levelLower(): int
        {
            return this._levelLower;
        }

        public get levelUpper(): int
        {
            return this._levelUpper;
        }

        /* internal */ /* var */_textInput: GTextInput;

        /* internal */ /* var */_searchBtn: GButton;

        /* internal */ /* var */_levelCombo: GComboBox;

        /* internal */ /* var */_colorCombo: GComboBox;

        /* internal */ /* var */_careerCombo: GComboBox;

        /* internal */ /* var */_levelDp: DataProvider;

        /* internal */ /* var */_colorDp: DataProvider;

        /* internal */ /* var */_careerDp: DataProvider;

        /* internal */ /* var */_levelLower: int=1;

        /* internal */ /* var */_levelUpper: int=100;

        /* internal */ /* var */_color: int=0;

        /* internal */ /* var */_career: int=0;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_stringList: SearchStringList;

        /* internal */ /* var */_searchDic: Map<any, any> /* flash.utils.Dictionary */;
    }
